/*
 * GNationalCup.java
 * Created on 26 mars 08
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2008, Jens and Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hockeo.vhbase.data.dao.contest;


import java.math.BigDecimal;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

import com.hockeo.vhbase.conf.GRulesConstants;
import com.hockeo.vhbase.data.dao.IGEntity;
import com.hockeo.vhbase.data.helper.GContestHistoryType;
import com.hockeo.vhbase.utils.lang.GMath;

/**
 * Represents a national hockey cup contest.
 *
 * @version $Id$
 * @author jjanke
 */
@Entity
@DiscriminatorValue( "CUP" )
public class GNationalCup extends GContest
{
  /**
   * Overridden to return the default implementation class name, if no specific one is
   * defined.
   */
  @Override
  public String getImplClass()
  {
    String strImplClass = super.getImplClass();

    if ( strImplClass == null )
      strImplClass = "defaultCupImpl";

    return strImplClass;
  }

  @Override
  public BigDecimal getRankingCoefficient()
  {
    return GRulesConstants.CONTEST_COEFFICIENT_NATIONAL_CUP;
  }

  @Override
  public GContestHistoryType getHistoryType()
  {
    return GContestHistoryType.NATIONAL_CUP;
  }

  /**
   * Returns the number of rounds that need to be played in the main contest of this
   * national cup. The main contest starts with the round in which all first league clubs
   * enter the competition. The number of participants in the first main round is
   * indicated by the number of teams {@link #getNumTeams()}.
   */
  public int getNumRoundsMainContest()
  {
    return (int) Math.ceil( Math.log10( getNumTeams() ) / GMath.LOG10_2 );
  }

  @Override
  public String getContestTypeIconPrefix()
  {
    return "cup_";
  }

  public Class<? extends IGEntity> getGEntityClass()
  {
    return GNationalCup.class;
  }
}
